package com.woniuxy.store.app.apiImpl;

import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.member.client.MemberManageClient;
import com.woniuxy.member.client.MemberQueryClient;
import com.woniuxy.member.client.param.AddMemberFoodParam;
import com.woniuxy.member.client.param.ExchangeFoodSearchParam;
import com.woniuxy.member.client.param.ModifyMemberFoodParam;
import com.woniuxy.member.client.result.ExchangeFoodClientDto;
import com.woniuxy.store.app.util.StoreIdUtil;
import com.woniuxy.store.client.MemberFoodClient;
import com.woniuxy.store.client.param.MemberExchangeParam.AddMemberFoodParams;
import com.woniuxy.store.client.param.MemberExchangeParam.ExchangeFoodSearchParams;
import com.woniuxy.store.client.param.MemberExchangeParam.ModifyMemberFoodParams;
import common.WoniuPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import result.Result;

import javax.validation.Valid;

@RestController
@RequestMapping("/store/marketing")
public class MemberFoodClientImpl implements MemberFoodClient {
    @Autowired
    private MemberManageClient memberManageClient;
    @Autowired
    private MemberQueryClient memberQueryClient;

    @Override
    public Result getScoreExchangeFood(@Valid ExchangeFoodSearchParams exchangeFoodSearchParams) {
        ExchangeFoodSearchParam exchangeFoodSearchParam = BeanUtil.toBean(exchangeFoodSearchParams, ExchangeFoodSearchParam.class);
        exchangeFoodSearchParam.setStoreId(StoreIdUtil.getFromToken());
        Result<WoniuPage<ExchangeFoodClientDto>> scoreExchangeFood = memberQueryClient.getScoreExchangeFood(exchangeFoodSearchParam);
        return scoreExchangeFood;
    }

    @Override
    public Result addMemberFood(@Valid AddMemberFoodParams addMemberFoodParams) {
        AddMemberFoodParam addMemberFoodParam = BeanUtil.toBean(addMemberFoodParams, AddMemberFoodParam.class);
        addMemberFoodParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = memberManageClient.addMemberFood(addMemberFoodParam);
        return result;
    }

    @Override
    public Result modifyMemberFood(@Valid ModifyMemberFoodParams modifyMemberFoodParams) {
        ModifyMemberFoodParam modifyMemberFoodParam = BeanUtil.toBean(modifyMemberFoodParams, ModifyMemberFoodParam.class);
        modifyMemberFoodParam.setStoreId(StoreIdUtil.getFromToken());
        Result result = memberManageClient.modifyMemberFood(modifyMemberFoodParam);
        return result;
    }

    @Override
    public Result delMemberFood(Integer exchangeFoodId) {
        memberManageClient.delMemberFood(StoreIdUtil.getFromToken(),exchangeFoodId);
        return null;
    }
}
